import { HttpService } from '@nestjs/axios/dist';
import { Injectable } from '@nestjs/common';
import { ExcelExportConfig } from './config';
import errors from './error';

@Injectable()
export class AppService {

  constructor(private http: HttpService) {

  }

  getHello(): string {
    return 'Hello World!';
  }

  getDataSource(config: ExcelExportConfig) {
    if (!config) throw errors.argumentNull("config");

    return new Promise<any[]>((resolve, reject) => {
      this.http.get(config.dataSource).subscribe({
        next: function (r) {
          resolve(r.data);
        },
        error: (err) => {
          reject(err);
        }
      })

    });

  }
}
